﻿var idMenu = 0;
$(document).ready(function () {
    //Set Hover submenu
    var isHoverParent = false;
    var isHoverSub = false;

    $('#liFlowerDesign').live('mouseover', function () {
        var position = $("#liFlowerDesign").position();
        //var widthli = $("#liFlowerDesign").outerWidth();
        //$("#divSubMenu").css({ "width": parseInt(widthli) + "px" });
        $("#divSubMenu").css({ "left": position.left + "px" });
        $("#divSubMenu").css({ "top": position.top + 32 + "px" });

        //$("#divSubMenu").show('fade');
        $("#divSubMenu").css("display", "");
        $("#divSubMenu").css("visibility", "visible");

        isHoverParent = true;
    });
    $('#liFlowerDesign').live('mouseout', function () {

        isHoverParent = false;
        $("#divSubMenu").live('mouseover', function () {
            //$("#divSubMenu").show().css("display", "");
            $("#divSubMenu").css("display", "");
            isHoverSub = true;
            $('#liFlowerDesign').css("background-color", "#FFFFFF");
        });
        $("#divSubMenu").live('mouseout', function () {
            $("#divSubMenu").css("display", "none");
            isHoverSub = false;
            $('#liFlowerDesign').css("background-color", "");
        });
        if (isHoverParent === false && isHoverSub === false) {
            $("#divSubMenu").css("display", "none");
        }
    });

    var isHoverParentWedding = false;
    var isHoverSubWedding = false;

    $('#liWedding').bind('mouseover', function () {
        var position = $("#liWedding").position();
        //var widthli = $("#liWedding").outerWidth();
        //$("#divSubMenuWedding").css({ "width": parseInt(widthli) + "px" });
        $("#divSubMenuWedding").css({ "left": position.left + "px" });
        $("#divSubMenuWedding").css({ "top": position.top + 32 + "px" });
        //$("#divSubMenuWedding").show('fade');
        $("#divSubMenuWedding").css("display", "");
        $("#divSubMenuWedding").css("visibility", "visible");
        isHoverParentWedding = true;
    });
    $('#liWedding').bind('mouseout', function () {

        isHoverParentWedding = false;
        $("#divSubMenuWedding").bind('mouseover', function () {
            $("#divSubMenuWedding").css("display", "");
            //$("#divSubMenuWedding").show('fade');
            isHoverSubWedding = true;
            $('#liWedding').css("background-color", "#FFFFFF");
        });
        $("#divSubMenuWedding").bind('mouseout', function () {
            $("#divSubMenuWedding").css("display", "none");
            isHoverSubWedding = false;
            $('#liWedding').css("background-color", "");
        });
        if (isHoverParentWedding === false && isHoverSubWedding === false) {
            $("#divSubMenuWedding").css("display", "none");
        }
    });

    //    var Browser = BrowserDetect.browser;
    //    if (Browser === 'Firefox' || Browser === 'Chrome') {
    //        $(".menu ul li").css("padding-bottom", "11px");
    //    }
    //    else
    //        if (Browser === 'Explorer') {  // IE

    //        }
    //        else { // other
    //            ;
    //        }


    //Set active menu for 
    var url = window.location.href;
    if (url.indexOf("Default") > 0)
        idMenu = 0;
    else
        if (url.indexOf("Flower") > 0)
            idMenu = 1;
        else
            if (url.indexOf("Weddings") > 0)
                idMenu = 2;
            else
                if (url.indexOf("Gift") > 0)
                    idMenu = 3;
                else
                    if (url.indexOf("news") > 0)
                        idMenu = 4;
                    else
                        if (url.indexOf("About") > 0)
                            idMenu = 5;
                        else
                            if (url.indexOf("Partner") > 0)
                                idMenu = 6;
                            else
                                if (url.indexOf("ContactUs") > 0)
                                    idMenu = 7;
    DeActiveAllTab(idMenu);
    /* ------------------- END ---------------*/

    GetImagePage();


});

function DeActiveAllTab(idTab) {
    $(".menu ul li").each(function (index) {
        if(idTab !== index)
            $(this).removeClass("active-menu");
        else
            $(this).addClass("active-menu");
    });
}

function GetImagePage() {
    $(".menu ul li").each(function (index) {
        if ($(this).hasClass('active-menu')) {
            var sMenu = $(this).text();
            $.ajax({
                url: "Common/Ajax.aspx/GetImgByName",
                type: "POST",
                //data: JSON.stringify({ 'sName': sMenu, 'IsActive': 1, 'IsDelete': 1 }),
                data: "{sName:'" + sMenu + "',IsActive:1,IsDelete:0}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) { GetImagePage_Succ(data); },
                error: function () { }
            });
        }
    });
}

function GetImagePage_Succ(data) {
    $("#imgOwn").attr("src", "Images/Flowers/" + data.d);
}